<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<style>
    div[lay-id="datalist"] .layui-table-cell{
        height:auto !important;
    };
</style>
<body class="laytp-container">
    <div style="height: 45px"></div>
    <div id="opt_nav">
    </div>
    <div id="dialog">
        <div class="page-title" id="page-title">
            <div class="page-title-con">
                <span class="title">选择证书信息</span>
                <div class="move_title"></div>
                <div class="page-title-opt-list">
                    <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                    <button class="layui-btn layui-btn-sm btn-dark marginr5 layui-hide emptyBut" style="background-color: #FFFFFF;color:#333;border:1px solid #ccc" type="button" id="empty">清空</button>
                    <span id="page-close" class="page-close" onclick="layer_close()">×</span>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-card" id="search-form">
        <div class="layui-card-body">
            <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-md3">
                            <label class="layui-form-label">所属单位</label>
                            <div class="layui-input-block">
                                <div id="chanid" class="xmselect_div">
                                    <div class="xmselect_title">请选择</div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <label class="layui-form-label">人员性质</label>
                            <div class="layui-input-block">
                                <div id="person_nature" class="xmselect_div">
                                    <div class="xmselect_title">请选择</div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <label class="layui-form-label">人员姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="person_name" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">证书名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" id="name" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">证书编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">证书专业</label>
                            <div class="layui-input-block">
                                <input type="text" name="major" id="major" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">发证单位</label>
                            <div class="layui-input-block">
                                <input type="text" name="issue_unit" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">注册/发证日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="issue_dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">有效期止</label>
                            <div class="layui-input-block">
                                <input type="text" name="expiry_dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">证书形式</label>
                            <div class="layui-input-block">
                                <select name="form" id="form"></select>
                            </div>
                        </div>
<!--                        <div class="layui-col-md3 search_hide none">-->
<!--                            <label class="layui-form-label">证书状态</label>-->
<!--                            <div class="layui-input-block">-->
<!--                                <select name="state" id="state"></select>-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">电子件有效期</label>
                            <div class="layui-input-block">
                                <input type="text" name="electron_dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">
                            </div>
                        </div>
<!--                        <div class="layui-col-md3 search_hide none">-->
<!--                            <label class="layui-form-label">下次年检时间</label>-->
<!--                            <div class="layui-input-block">-->
<!--                                <input type="text" name="inspect_dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="layui-col-md3 search_hide none">-->
<!--                            <label class="layui-form-label">保管人</label>-->
<!--                            <div class="layui-input-block">-->
<!--                                <input type="text" name="custodianid" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="layui-col-md3 search_hide none">-->
<!--                            <label class="layui-form-label">存放地</label>-->
<!--                            <div class="layui-input-block">-->
<!--                                <div id="store_addr" class="xmselect_div">-->
<!--                                    <div class="xmselect_title">请选择</div>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">证书去向</label>
                            <div class="layui-input-block">
                                <select name="goes" id="goes"></select>
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">使用情况</label>
                            <div class="layui-input-block">
                                <select name="statueuse" id="statueuse"></select>
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">人员状态</label>
                            <div class="layui-input-block">
                                <select name="person_state" id="person_state">
                                    <option value="">请选择</option>
                                    <option value="在职">在职</option>
                                    <option value="离职">离职</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-col-md3">
                            <div class="layui-form-item search-div">
                                <div class="layui-form-item layui-inline">
                                    <input type="hidden" id="type" name="type" value="">
                                    <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                    <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                    <div id="search_open" onclick="toggle_search()">
                                        <i class="layui-icon layui-icon-down"></i>展开
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <div class="layui-card" id="table-card">
        <div class="layui-card-body">
            <div class="layui-row">
                <?php include '../cert/dao.php' ?>

                <div class="layui-col-md10" id="table_list">
                    <div class="layui-card-body">
                        <table id="datalist" lay-filter="datalist"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        // 单选多选分类 默认单选 choose_type传值为多选
        var choose_type = getQueryVariable('choose_type');
        if(choose_type === undefined || choose_type === false){
            choose_type = 'radio';
        }else{
            choose_type = 'checkbox';
        }


        var parent_dom = getQueryVariable('dom');
        var parent_page = getQueryVariable('page');
        var parent_index = getQueryVariable('index');
        var parent_isborrow = getQueryVariable('isborrow') || '';

        if(parent_page === 'achievemul'){
            $(".emptyBut").removeClass('layui-hide');
        }


        var currButAuth, currTabData;
        layui.use(['laytp','tree','table','form','soulTable'], function () {
            var tree = layui.tree, table = layui.table, form = layui.form, soulTable = layui.soulTable;

            $('#TableSearchReset').click(function () {
                $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
                $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
                searchTableFunc(form, table)
            });

            $("#cols_table").hide();
            $("#export_table").hide();
            table.render({
                elem: '#datalist'
                ,toolbar: false
                ,defaultToolbar: ['', '', '']
                ,method:'post'
                ,url: facade.url(ask_opt_get_cert)
                ,page: true
                ,where: {isborrow:parent_isborrow}
                ,request: {pageName: 'page',limitName: 'pagesize'}
                ,parseData: function(res){
                    var formArr = res.data.form;
                    var form_str = '<option value="">请选择</option>';
                    for(var i in formArr){
                        if(res.data.is_form == i){
                            form_str += '<option value="'+i+'" selected>'+formArr[i]+'</option>';
                        }else{
                            form_str += '<option value="'+i+'">'+formArr[i]+'</option>';
                        }
                    }
                    $('#form').html(form_str);

                    var stateArr = res.data.state;
                    var state_str = '<option value="">请选择</option>';
                    for(var i in stateArr){
                        if(res.data.is_state == i){
                            state_str += '<option value="'+i+'" selected>'+stateArr[i]+'</option>';
                        }else{
                            state_str += '<option value="'+i+'">'+stateArr[i]+'</option>';
                        }
                    }
                    $('#state').html(state_str);

                    var goesArr = res.data.goes;
                    var goes_str = '<option value="">请选择</option>';
                    for(var i in goesArr){
                        if(res.data.is_goes == i){
                            goes_str += '<option value="'+i+'" selected>'+goesArr[i]+'</option>';
                        }else{
                            goes_str += '<option value="'+i+'">'+goesArr[i]+'</option>';
                        }
                    }
                    $('#goes').html(goes_str);

                    var statueuse = res.data.statueuse;
                    var statueuse_str = '<option value="">请选择</option>';
                    for(var i in statueuse){
                        if(res.data.is_statueuse == i){
                            statueuse_str += '<option value="'+i+'" selected>'+statueuse[i]+'</option>';
                        }else{
                            statueuse_str += '<option value="'+i+'">'+statueuse[i]+'</option>';
                        }
                    }
                    $('#statueuse').html(statueuse_str);

                    xmselect_dan('chanid', res.data.chanid, res.data.is_chanid, function (res) {
                        setTimeout(function () {
                            searchTableFunc(form, table);
                        },100)
                    })
                    xmselect_dan('person_nature', res.data.nature, res.data.is_nature, function (res) {
                        setTimeout(function () {
                            searchTableFunc(form, table);
                        },100)
                    })
                    xmselect_dan('store_addr', res.data.store_addr, res.data.is_store_addr, function (res) {
                        setTimeout(function () {
                            searchTableFunc(form, table);
                        },100)
                    })

                    render_from();
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.data.total,
                        "data": res.data.data.data
                    };
                }
                ,response: {statusCode: 2000}
                ,cols: [[
                    {type:choose_type,fixed:'left'}
                    ,{type:'numbers',title:'序号',fixed:'left'}
                    ,{field: 'name', title: '证书名称',width: 100}
                    ,{field: 'person_name', title: '持证人',width: 100}
                    ,{field: 'person_nature', title: '人员性质',width: 100}
                    ,{field: 'chanid_name', title: '所属单位',width: 100}
                    ,{field: 'type', title: '证书分类',width: 100}
                    ,{field: 'number', title: '证书编号',width: 100}
                    ,{field: 'major', title: '证书专业',width: 100}
                    ,{field: 'expiry_dt', title: '有效期止',width: 100}
                    ,{field: 'issue_unit', title: '发证单位',width: 100}
                    // ,{field: 'issue_dt', title: '注册/发证日期',hide:true}
                    ,{field: 'form_name', title: '证书形式',width: 100}
                    ,{field: 'state_name', title: '证书状态',width: 100}
                    ,{field: 'goes_name', title: '证书去向',width: 100}
                    ,{field: 'statueuse_name', title: '使用情况',width: 100}
                    ,{field: 'person_statueuse_name', title: '人员状态',width: 100}
                    // ,{field: 'electron_dt', title: '电子件有效期',hide:true}
                    // ,{field: 'inspect_dt', title: '下次年检时间',hide:true}
                    // ,{field: 'store_addr', title: '存放地',width: 100}
                    // ,{field: 'custodian_name', title: '保管人',width: 100}
                    // ,{field: 'explain', title: '备注',hide:true}
                ]]
                // 重选设置默认选中
                ,done : function(res, curr, count){
                    soulTable.render(this);

                    // 处理列表fixed的高度问题
                    $('div[lay-id="datalist"] .layui-table-main>table>tbody>tr').each(function (i) {
                        var height = $(this).height();
                        $('div[lay-id="datalist"] .layui-table-fixed-l>.layui-table-body>table>tbody>tr')
                            .eq(i).css('cssText','height:'+height+'px !important');
                        $('div[lay-id="datalist"] .layui-table-fixed-r>.layui-table-body>table>tbody>tr')
                            .eq(i).css('cssText','height:'+height+'px !important');
                    });
                }
            });

            listTableSearch(form, table);


            $('#submit').on('click', function () {
                var checkStatus = layui.table.checkStatus('datalist');
                var data = checkStatus.data;
                if(data.length === 0){
                    facade.error('请选择数据'); return false;
                }

                if(parent_page === 'achieve'){
                    var str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].id+'"><span class="choose_content">'+data[0].person_name+'('+data[0].name+')' +
                        '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                    $("#"+parent_dom , parent.document).html(str);
                    parent.formValid(parent_dom);
                }else if(parent_page === 'achievemul'){
                    $("#list_list tr", parent.document).eq(parent_index).find('.'+parent_dom).val(data[0].person_name+'('+data[0].name+')');
                    $("#list_list tr", parent.document).eq(parent_index).find('.'+parent_dom).attr('key',data[0].id);
                }else if(parent_page === 'cert_use'){
                    var placeArr = parent.placeArr;
                    var str = '';
                    var nums = $("#list_list tr", parent.document).length;
                    for (var key in data){
                        nums++;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><select class="layui-select place">';
                        str += '<option value="">请选择</option>';
                        for (var mmm in placeArr) {
                            str += '<option value="'+placeArr[mmm]+'">'+placeArr[mmm]+'</option>';
                        }
                        str += '</select></td>';
                        str += '<td><input type="text" onclick="check_cert_one(this)" certid="'+data[key].id+'" readonly value="'+data[key].name+'" class="layui-input disabled name"></td>';
                        str += '<td><input type="text" class="layui-input numberss disabled" readonly value="'+data[key].number+'"></td>';
                        str += '<td><input type="text" class="layui-input major_name disabled" readonly value="'+data[key].major_name+'"></td>';
                        str += '<td><input type="text" class="layui-input person_name disabled" readonly value="'+data[key].person_name+'"></td>';
                        str += '<td><input type="text" class="layui-input statueuse_name disabled" readonly value="'+data[key].statueuse_name+'"></td>';
                        str += '<td><input type="text" class="layui-input chanid_name disabled" readonly value="'+data[key].chanid_name+'"></td>';
                        str += '<td><select class="layui-select issuo">';
                        str += '<option value="是">是</option>';
                        str += '<option value="否" selected>否</option>';
                        str += '</select></td>';
                        str += '<td><input type="number" class="layui-input usefee"></td>';
                        str += '<td><input type="text" class="layui-input startdt bdate_ymd" readonly></td>';
                        str += '<td><input type="text" class="layui-input yudt bdate_ymd" readonly></td>';
                        str += '<td><input type="text" class="layui-input enddt bdate_ymd" readonly></td>';
                        str += '<td><select class="layui-select opt">';
                        str += '<option value="1" selected>在用</option>';
                        str += '<option value="0">停用</option>';
                        str += '</select></td>';
                        str += '</tr>';
                    }
                    $("#list_list", parent.document).append(str);
                    if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                        window.parent.update_refresh_row_func();
                    }
                    parent.render_date();
                    parent.render_from();
                }else if(parent_page === 'cert_use_one'){
                    $("#list_list tr", parent.document).eq(parent_index).find('.name').val(data[0].name).attr('certid',data[0].id);
                    $("#list_list tr", parent.document).eq(parent_index).find('.numberss').val(data[0].number);
                    $("#list_list tr", parent.document).eq(parent_index).find('.major_name').val(data[0].major_name);
                    $("#list_list tr", parent.document).eq(parent_index).find('.person_name').val(data[0].person_name);
                    $("#list_list tr", parent.document).eq(parent_index).find('.statueuse_name').val(data[0].statueuse_name);
                    $("#list_list tr", parent.document).eq(parent_index).find('.chanid_name').val(data[0].chanid_name);
                    if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                        window.parent.update_refresh_row_func();
                    }
                }else if(parent_page === 'cert_use_bid'){
                    var placeArr = parent.placeArr;
                    var str = '';
                    var nums = $("#list_list tr", parent.document).length;
                    for (var key in data){
                        nums++;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><select class="layui-select place">';
                        str += '<option value="">请选择</option>';
                        for (var mmm in placeArr) {
                            str += '<option value="'+placeArr[mmm]+'">'+placeArr[mmm]+'</option>';
                        }
                        str += '</select></td>';
                        str += '<td><input type="text" onclick="check_cert_one(this)" certid="'+data[key].id+'" readonly value="'+data[key].name+'" class="layui-input disabled name"></td>';
                        str += '<td><input type="text" class="layui-input numberss disabled" readonly value="'+data[key].number+'"></td>';
                        str += '<td><input type="text" class="layui-input major_name disabled" readonly value="'+data[key].major_name+'"></td>';
                        str += '<td><input type="text" class="layui-input person_name disabled" readonly value="'+data[key].person_name+'"></td>';
                        str += '<td><input type="text" class="layui-input statueuse_name disabled" readonly value="'+data[key].statueuse_name+'"></td>';
                        str += '<td><input type="text" class="layui-input chanid_name disabled" readonly value="'+data[key].chanid_name+'"></td>';
                        str += '<td><select class="layui-select opt">';
                        str += '<option value="1" selected>在用</option>';
                        str += '<option value="0">停用</option>';
                        str += '</select></td>';
                        str += '</tr>';
                    }
                    $("#list_list", parent.document).append(str);
                    if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                        window.parent.update_refresh_row_func();
                    }
                    parent.render_date();
                    parent.render_from();
                }else if(parent_page === 'cert_use_bid_one'){
                    $("#list_list tr", parent.document).eq(parent_index).find('.name').val(data[0].name).attr('certid',data[0].id);
                    $("#list_list tr", parent.document).eq(parent_index).find('.numberss').val(data[0].number);
                    $("#list_list tr", parent.document).eq(parent_index).find('.major_name').val(data[0].major_name);
                    $("#list_list tr", parent.document).eq(parent_index).find('.person_name').val(data[0].person_name);
                    $("#list_list tr", parent.document).eq(parent_index).find('.statueuse_name').val(data[0].statueuse_name);
                    $("#list_list tr", parent.document).eq(parent_index).find('.chanid_name').val(data[0].chanid_name);
                    if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                        window.parent.update_refresh_row_func();
                    }
                }else if(parent_page === 'cert_borrow'){
                    var str = '';
                    var nums = $("#list_list tr", parent.document).length;
                    for (var key in data){
                        nums++;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td>';
                        str += '<input type="text" certid="'+data[key].id+'" certtype="1" disabled value="'+data[key].name+'-'+data[key].person_name+'" class="layui-input disabled name">';
                        str += '</td>';
                        str += '<td><input type="text" class="layui-input disabled major" disabled value="'+data[key].major_name+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled number" disabled value="'+data[key].number+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled form_name" disabled value="'+data[key].form_name+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled goes_name" disabled value="'+data[key].goes_name+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled chanid_name" disabled value="'+data[key].chanid_name+'"></td>';
                        str += '</tr>';
                    }
                    $("#list_list", parent.document).append(str);
                    if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                        window.parent.update_refresh_row_func();
                    }
                }else if(parent_page === 'cert_down'){
                    var str = '';
                    var nums = $("#list_list tr", parent.document).length;
                    for (var key in data){
                        nums++;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td>';
                        str += '<input type="text" certid="'+data[key].id+'" certtype="1" disabled value="'+data[key].name+'-'+data[key].person_name+'" class="layui-input disabled name">';
                        str += '</td>';
                        str += '<td><input type="text" class="layui-input disabled major" disabled value="'+data[key].major_name+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled number" disabled value="'+data[key].number+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled form_name" disabled value="'+data[key].form_name+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled goes_name" disabled value="'+data[key].goes_name+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled chanid_name" disabled value="'+data[key].chanid_name+'"></td>';
                        str += '</tr>';
                    }
                    $("#list_list", parent.document).append(str);
                    if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                        window.parent.update_refresh_row_func();
                    }
                }


                if(parent_page === 'engin_beian'){
                    var index = getQueryVariable('index');
                    $("#beian_list tr", parent.document).eq(index-1).find('.certid').val(data[0].id);
                    $("#beian_list tr", parent.document).eq(index-1).find('.cert_name').val(data[0].name);
                    $("#beian_list tr", parent.document).eq(index-1).find('.cert_number').val(data[0].number);
                    $("#beian_list tr", parent.document).eq(index-1).find('.cert_major').val(data[0].major_name);
                    $("#beian_list tr", parent.document).eq(index-1).find('.person_name').val(data[0].person_name);
                    parent.render_from();
                }





                if(!parent_page){
                    $("#"+parent_dom+'_name' , parent.document).val(data[0].person_name+'('+data[0].name+')');
                    $("#"+parent_dom , parent.document).val(data[0].id);
                }

                layer_close();
            });

            // 清空
            $('#empty').on('click', function () {
                if(parent_page === 'achievemul'){
                    $("#list_list tr", parent.document).eq(parent_index).find('.'+parent_dom).val('');
                    $("#list_list tr", parent.document).eq(parent_index).find('.'+parent_dom).attr('key',0);
                }
                layer_close();
            });
        });
    </script>
</body>
</html>
